package com.tengniu.web.controller.buss;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tengniu.buss.domain.MassageChairPackage;
import com.tengniu.buss.domain.MassageChairPackageDetail;
import com.tengniu.buss.service.MassageChairPackageDetailService;
import com.tengniu.buss.service.MassageChairPackageService;
import com.tengniu.common.annotation.Log;
import com.tengniu.common.buss.enums.YesOrNoEnum;
import com.tengniu.common.core.controller.BaseController;
import com.tengniu.common.core.domain.AjaxResult;
import com.tengniu.common.core.page.TableDataInfo;
import com.tengniu.common.enums.BusinessType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 按摩椅套餐明细管理
 */
@RestController
@RequestMapping("/admin/packageDetail")
@Slf4j
public class PackageDetailAdminController extends BaseController {

    @Resource
    private MassageChairPackageDetailService massageChairPackageDetailService;

    /**
     * 获取按摩椅套餐明细
     */
    @PreAuthorize("@ss.hasPermi('buss:packageDetail:list')")
    @GetMapping("/list/{packageId}")
    public AjaxResult list(@PathVariable Long packageId) {
        List<MassageChairPackageDetail> list = massageChairPackageDetailService.list(
                Wrappers.lambdaQuery(MassageChairPackageDetail.class)
                        .eq(MassageChairPackageDetail::getPackageId, packageId)
                        .orderByAsc(MassageChairPackageDetail::getDetailSort));
        return AjaxResult.success(list);
    }

    /**
     * 新增按摩椅套餐明细
     */
    @PreAuthorize("@ss.hasPermi('buss:packageDetail:add')")
    @Log(title = "按摩椅套餐", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody MassageChairPackageDetail massageChairPackageDetail) {
        return toAjax(massageChairPackageDetailService.save(massageChairPackageDetail));
    }

    /**
     * 修改按摩椅套餐明细
     */
    @PreAuthorize("@ss.hasPermi('buss:packageDetail:edit')")
    @Log(title = "按摩椅套餐", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody MassageChairPackageDetail massageChairPackageDetail) {
        return toAjax(massageChairPackageDetailService.updateById(massageChairPackageDetail));
    }

    /**
     * 删除按摩椅套餐明细
     */
    @PreAuthorize("@ss.hasPermi('buss:packageDetail:remove')")
    @Log(title = "按摩椅套餐", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{detailId}")
    public AjaxResult remove(@PathVariable Long detailId) {
        return toAjax(massageChairPackageDetailService.removeById(detailId));
    }

}
